#include "Light.h"
#include "Global.h"
#include "Basic/Stream.h"

namespace FinalRendering
{
	namespace Engine
	{
		Light * Light::FromEntity(IEntity * ent)
		{
			IBspEntity * bspEntity = dynamic_cast<IBspEntity*>(ent);
			if (bspEntity && wcscmp(ent->GetDesc()->ClassName(), L"Light") == 0)
			{
				Light * rs = new Light();
				Volume vol;
				bspEntity->GetVolume(&vol);
				rs->Position = vol.Position;
				bspEntity->ProcessMessage(0, EntityMessage(L"GetColor", (int)(&rs->Color)));
				bspEntity->ProcessMessage(0, EntityMessage(L"GetCutOff", (int)(&rs->CutOff)));
				bspEntity->ProcessMessage(0, EntityMessage(L"GetDir", (int)(&rs->Dir)));
				bspEntity->ProcessMessage(0, EntityMessage(L"GetDistanceFull", (int)(&rs->DistanceFull)));
				bspEntity->ProcessMessage(0, EntityMessage(L"GetDistanceHalf", (int)(&rs->DistanceHalf)));
				bspEntity->ProcessMessage(0, EntityMessage(L"GetPower", (int)(&rs->Power)));
				return rs;
			}
			return 0;
		}

	}
}